<template>
    <h2 style="text-align: center;">登录</h2>
    <table border="1" class="table table-bordered">
        <tbody>
            <tr>
                <th>会员名称</th>
                <th>
                    <input type="text" placeholder="请输入会员名称" v-model="Info.Member_Name" />
                </th>
            </tr>

            <tr>
                <th>会员密码</th>
                <th>
                    <input type="password" v-model="Info.Member_Password"/>
                </th>
            </tr>

            <tr>
                <th colspan="2" style="text-align: center;">
                    <input type="button" value="登录" class="btn btn-success"  @click="Login"/>
                </th>
            </tr>
        </tbody>
    </table>
</template>


<script setup lang="ts">
    import {ref} from 'vue';
    import axios from 'axios';
    import { useRouter } from 'vue-router';

    const router=useRouter();
    const Info=ref({
        Member_Id: 0,
        Member_Name: "",
        Member_Password: "",
    })
    //登录
    const Login=()=>{
        axios.get("https://localhost:44390/api/Member/Login",
            {
                params:{
                    name:Info.value.Member_Name,
                    password:Info.value.Member_Password,
                }
            }
        )
        .then(res=>{
            if(res.data.Member_Id==-1)
            {
                alert('会员名称错误！');
                return;
            }
            else if(res.data.Member_Id==-2)
            {
                alert('会员密码错误！');
                return;
            }
            else if(res.data.Member_Id>0)
            {
                alert('登录成功');
                router.push("/ShowMember");
            }
        })
    }
</script>